637B - Chat Order - CodeForces Solution


*special problem binary search constructive algorithms data structures sortings *1200

Please click on ads to support us..

Python Code:

s = set()
l = list()
n = int(input())
for _ in range(n):
  l.append(input())
for i in range(n-1,-1,-1):
  if l[i] not in s:
    s.add(l[i])
    print(l[i])

C++ Code:

#define ll long long
#define MAXN 200010
#define INF 0x3f3f3f3f
#include <bits/stdc++.h>
using namespace std;

stack<string> a;
set<string> r;

int main(){
#ifdef _DEBUG
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
#define int ll
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        a.push(s);
    }
    while (!a.empty()) {
        if (!r.count(a.top())) {
            cout << a.top() << endl;
            r.insert(a.top());
        }
        a.pop();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

645A - Amity Assessment
1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring
630N - Forecast
312B - Archer
34D - Road Map
630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya
137B - Permutation
550C - Divisibility by Eight
5A - Chat Servers Outgoing Traffic
615A - Bulbs
5B - Center Alignment
549A - Face Detection
535B - Tavas and SaDDas
722C - Destroying Array
366A - Dima and Guards
716B - Complete the Word
1461C - Random Events
1627A - Not Shading
141B - Hopscotch
47B - Coins
1466C - Canine poetry
74A - Room Leader
1333D - Challenges in school №41
1475B - New Year's Number
461A - Appleman and Toastman